﻿using System;
using System.IO;
using LFSRecord2.Model.Replay;

namespace LFSRecord2.Model.Media
{
    public class MediaReplayData : MediaBase
    {
        public ReplayData RData { get; private set; }

        public MediaReplayData(string filePath)
        {
            MediaType = MediaTypes.ReplayData;
            IconType = MediaIconTypes.ReplayData;

            FilePath = filePath;
            FileStatus = MediaFileStatus.None;

            // Import file?
            if (FilePath.Length > 0)
            {
                loadFile();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                RData = null;
            }
        }

        public override void ReloadFile()
        {
            resetFileInfo();

            // Import file?
            if (FilePath.Length > 0)
            {
                loadFile();
            }
        }

        protected override void ImportFile()
        {
            // Check if file exists
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException();
            }

            // Setup new RData object
            RData = new ReplayData();

            // Load the rdata
            try
            {
                RData.Load(FilePath);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            populateFileInfo();
        }
    }
}
